﻿@model IEnumerable<SketchTour.Models.MSRM00Models>
@{
    ViewBag.Title = "Permission";
}
<script type="text/javascript" language="javascript">
    function ChangeRow(pIndex, strThis) {
        var hdnRowChanged = document.getElementById("hdnRowChanged" + pIndex);
        hdnRowChanged.value = "True";

        var strRowChange = document.getElementById("rowValueChange" + pIndex);
        var strRowChange_Value = strRowChange.value;
        var strCheckbox_Name = strThis.name;


        if (strRowChange_Value.indexOf(strThis.name) !== -1) {
            
            var strRepl_value = strRowChange_Value.replace(strCheckbox_Name + ";", "");
            strRowChange.value = strRepl_value;
        } else {
            if (strRowChange_Value.length == 0) {
                strRowChange.value = strThis.name + ";";
            } else {
                strRowChange.value = strRowChange_Value + strThis.name + ";";
            }
        }
        if (strThis.checked == true) {
           
        } else {
            
        }
    }
</script>
<script language="javascript" type="text/javascript">
    $(function () {
        $('#listRoleName').change(function () {
            try {
                var strValue = $('#listRoleName option:selected').val();
                redirectionToAction('MSRM00', 'Permission', strValue)
//                $.ajax({
//                    url: 'MSRM00/setChangeRole',
//                    type: 'POST',
//                    contentType: 'application/json;',
//                    data: JSON.stringify({ id: strValue }),
//                    success: function (data) {

//                        if (data.success) { //show that id is valid 
//                            window.location.href = data.redirectUrl;
//                        }
//                        else { //show that id is not valid 
//                            alert("False");
//                        }
//                    }
//                });
            } catch (e)
                { alert(e); }
        });
        });

        function redirectionToAction(controller, action, id) {
            var url = "../../" + controller + "/" + action + "/"
            if (id != undefined)
                url += id;
            window.location = url;
        }
    </script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <div id="main">
        <!-- InstanceBeginEditable name="EditRegion1" -->
        <h2>
            Permission Role</h2>
        <!-- InstanceEndEditable -->
        <div id="error" class="error">
        </div>
        <div id="Div1" class="success">
        </div>
        <!-- InstanceBeginEditable name="EditRegion2" -->
        <p>
        </p>
        <p>
        </p>
        <table class="inputForm">
            <tbody>
                <tr>
                    <th>
                        Role Name
                    </th>
                    <td>
                        @*<select class="txt125">
                            <option>&nbsp;</option>
                            <option selected="true">Administrator</option>
                            <option>User</option>
                            <option>Guest</option>
                        </select>*@
                         @Html.DropDownList("listRoleName", (SelectList)ViewBag.listRoles, string.Empty)
                    </td>
                </tr>
            </tbody>
        </table>
        <table class="data-table">
            <tbody>
                <tr bgcolor="D8E6FC">
                    <th style="text-align: center;" scope="col" class="th150">
                        Screen Code
                    </th>
                    <th style="text-align: center;" scope="col" class="th200">
                        Screen Name
                    </th>
                    <th style="text-align: center;" scope="col" class="th50">
                        Note
                    </th>
                    <th style="text-align: center;" scope="col" class="th50">
                        View
                    </th>
                    <th style="text-align: center;" scope="col" class="th50">
                        Insert
                    </th>
                    <th style="text-align: center;" scope="col" class="th50">
                        Update
                    </th>
                    <th style="text-align: center;" scope="col" class="th50">
                        Delete
                    </th>
                    <th style="text-align: center;" scope="col" class="th50">
                        Full
                    </th>
                </tr>
                @{
    // private Ivs.Core.Mapping.EFBaseDao db = new Ivs.Core.Mapping.EFBaseDao();
    var k = 0;
    int index = 0;
    SketchTour.DAL.MSRM00DAL Dal = new SketchTour.DAL.MSRM00DAL();
    List<Ivs.Core.Mapping.m_function> listFunc = Dal.getAll_Function();
    System.Collections.Hashtable htbIndex = Dal.ConvertFunctionCodeToIndex(listFunc);
                }
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.ScreenCode)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.ScreenName)
                        </td>
                        <td style="text-align: center;">
                            &nbsp;
                        </td>
                        @for (int i = 0; i < listFunc.Count; i++)
                        {
                            index = Ivs.Core.Common.Utilities.Utilities.parseInt(htbIndex[listFunc[i].ID]);

                            //index = Ivs.Core.Common.Utilities.Utilities.parseInt(listFunc[i].ID);
                            // string idCheckbox = (listFunc[i].ID.ToString() + k).ToString();
                            string hidenAction_RowIndex = listFunc[i].ID.ToString() + "_" + k;
                            <td style="text-align: center;">
                                @Html.CheckBox(hidenAction_RowIndex, item.ScreenFunction[index], new { @onchange = "ChangeRow(" + k + "," + "this" + ")" })
                            </td>
                        }
                    </tr>
                    @Html.Hidden("rowValueChange" + k,"")
                    @Html.Hidden("hdfScreenId" + k, item.ScreenCode.ToString())
                    @Html.Hidden("hdfScreenCode" + k, item.ScreenCode.ToString())
                    @Html.Hidden("hdnRowChanged" + k)
                        k++;
                }
                @Html.Hidden("hdfNumRow", k)
                @Html.Hidden("hdfConfirmUpdate", ViewData["CONFIRM_UPDATE"] != null ? ViewData["CONFIRM_UPDATE"].ToString() : "")
                @Html.Hidden("hdfRoleId", ViewData["ROLE_ID"] != null ? ViewData["ROLE_ID"] : null)
            </tbody>
        </table>
        <div class="pager">
            <label class="disabled">
                &lt;&lt;</label><label class="disabled">&lt;</label><label class="current">1</label><label
                    class="disabled">&gt;</label><label class="disabled">&gt;&gt;</label>
        </div>
        <input type="submit" value="Save" class="btn50" onclick="window.location.href='/MSRM00'" />
        <input name="btnBack" type="button" value="Back" onclick="location.href='/MSRM00'" />
        <!-- InstanceEndEditable -->
    </div>
}
